package com.xxx.rpc.common.util;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;

import com.xxx.rpc.common.util.threadpool.ThreadPool;

 

/**
 * 全局对象
 *
 * @author rosun
 *
 * ihavecar web server framework
 * WebSite: https://github.com/notyet/roscat
 * Licence: Apache v2 License
 */
public class Global {

    private static ThreadPoolExecutor threadPool;
    
    
    private static ScheduledExecutorService scheduledTimer = null;

    /**
     * 返回公用线程池
     * @return 公用线程池
     */
    public static ThreadPoolExecutor getThreadPool(){
       if(threadPool==null || threadPool.isShutdown()){
           threadPool = ThreadPool.getNewThreadPool();
       }
       return threadPool;
    }
    
    public static ScheduledExecutorService getScheduledTimer(){
    	if(scheduledTimer == null){
    		scheduledTimer =  new ScheduledThreadPoolExecutor(1); 
    	}
    	return scheduledTimer;
    }
    
    
    public static void startTimerTask(){
    	getThreadPool().execute(new Runnable() {
			//FIXME 修改为注解扫描 后启动定时任务....
			@Override
			public void run() {
				//FIXME
			}
		});
    	
    }
    
    
}
